<%@ page contentType="text/html;charset=utf-8" language = "java" %>
<jsp:directive.page import="java.io.File"/>
<jsp:directive.page import="java.io.FileInputStream"/>
<jsp:directive.page import="java.io.FileOutputStream"/>
<jsp:directive.page import="java.io.BufferedInputStream"/>
<jsp:directive.page import="java.io.BufferedOutputStream"/>
<jsp:directive.page import="java.io.OutputStream"/>
<jsp:directive.page import="com.zte.eas.sox.business.operationlog.service.ISsbLogDS"/>
<jsp:directive.page import="com.zte.eas.sox.business.operationlog.service.IEasSaveOperationLog"/>
<jsp:directive.page import="com.zte.ssb.logmanager.business.model.AppLogInfoEntity"/>

<%
   AppLogInfoEntity log = new AppLogInfoEntity();
   //设置日志对象各属性,查询条件时用
   String parameter = request.getParameter("userId");
   if(null != parameter)
   {
	   log.setUserId(parameter);
   }
   
   parameter = request.getParameter("userName");
   if(null != parameter)
   {
	   //本地中文先转码,服务器上不用
	   //parameter = new String(parameter.getBytes("ISO-8859-1"),"UTF-8");
	   log.setUserName(parameter);
   }
   
   parameter = request.getParameter("userIp");
   if(null != parameter)
   {
	   log.setUserIp(parameter);
   }
   //操作类型
   parameter = request.getParameter("optType");
   if(null != parameter)
   {
	   //本地中文先转码,服务器上不用
	   //parameter = new String(parameter.getBytes("ISO-8859-1"),"UTF-8");
	   log.setOptType(parameter);
   }
   
   //业务对象
   parameter = request.getParameter("optObject");
   if(null != parameter)
   {
	   //本地中文先转码,服务器上不用
	   //parameter = new String(parameter.getBytes("ISO-8859-1"),"UTF-8");
	   log.setOptObject(parameter);
   }
   
   parameter = request.getParameter("time1");
   if(null != parameter)
   {
	   log.setStartTime(parameter);
   }
   parameter = request.getParameter("time2");
   if(null != parameter)
   {
	   log.setEndTime(parameter);
   }
   String contextPath = application.getRealPath("/");
   IEasSaveOperationLog easSaveOperationLog = (IEasSaveOperationLog)com.zte.ssb.framework.SSBBus.findDomainService("easSaveOperationLog");
   //导出
   easSaveOperationLog.export(log,contextPath);
   
   FileInputStream fis=null;
   fis = new FileInputStream(contextPath + File.separator + "log.zip");
	BufferedInputStream bis=new BufferedInputStream(fis);
	out.clear();
	String fileName = "log.zip";
	response.setContentType("APPLICATION/OCTET-STREAM");
	response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
	OutputStream os=response.getOutputStream();
	BufferedOutputStream bos=new BufferedOutputStream(os);
	byte[]cbuf=new byte[1024];

	while(bis.read(cbuf)!=-1){
		bos.write(cbuf);
	}
	bos.flush();
	try{
		bos.close();
	} catch (java.io.IOException e){
		e.printStackTrace();
	}
	try{
		bis.close();
	} catch (java.io.IOException e){
		e.printStackTrace();
	}
	
	//导完了删除文件
	easSaveOperationLog.delteFile(contextPath);
%>